//
//  NSObject+Alert.m
//  BabyListening
//
//  Created by ZhàoYǒng on 30/10/2017.
//  Copyright © 2017 ZhàoYǒng. All rights reserved.
//

#import "NSObject+Alert.h"
#import <UIKit/UIKit.h>

@implementation NSObject(Alert)

+ (void)showAlert:(NSString *)text selection:(void(^)(BOOL))selection {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:text preferredStyle:UIAlertControllerStyleAlert];
    if (selection) {
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            selection(NO);
        }];
        [alert addAction:confirm];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            selection(YES);
        }];
        [alert addAction:cancel];
    } else {
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:confirm];
    }
    [UIApplication.sharedApplication.keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
}

@end
